﻿$(document).ready(function(){
    list = getObjectList();
	generateList(list);
    $("#all").click(function(){
    	$('#chbI1').attr('checked',$('#chbI1').attr('checked')?false:true);
        $('#chbI2').attr('checked', $('#chbI2').attr('checked')?false:true);
        $('#chbO').attr('checked', $('#chbO').attr('checked')?false:true);
        $('#chbKURS').attr('checked', $('#chbKURS').attr('checked')?false:true);
        $('#chbSEMINARIUM').attr('checked', $('#chbSEMINARIUM').attr('checked')?false:true);
        $('#chbPROJEKT').attr('checked', $('#chbPROJEKT').attr('checked')?false:true);
        WindOfChange();
    });
    $("#ukryjFiltry").click(function(){
        $("#searchbar").toggle();
        var text = $("#ukryjFiltry").text();
        $("#ukryjFiltry").text(text=='Pokaż'?'Ukryj':'Pokaż');
    });
    var listashow = true;
    $("#ukryjLista").click(function(){
        if(listashow){
            $("#listbar").hide();
            $("#mainbar").removeClass().addClass("mainbarAlt");
        } else {
            $("#listbar").show();
            $("#mainbar").removeClass().addClass("mainbar");
        }
        var text = $("#ukryjLista").text();
        $("#ukryjLista").text(text=='>'?'<':'>');
        listashow = !listashow;

    });
    $(".link").click(function(){
        return false;
    });
    $(".param").keypress(function(e) {
            if(e.which == 10 || e.which == 13) {
                return false;
            }
        });
	$(".param").change(function(){WindOfChange()});
	$(".param").keyup(function(){WindOfChange()});
    $("#P01u").click(function(){
        alert('aaa');
    });
    $('.small').click(function(){
        var name = this.id;
        if(name=='P01del'){ // algebra
            hideAlgebra();
        } else if (name=='P17del'){ // erlang
            hideErlang();
        } else if (name=='P13del'){ // jfizo
            hideJfizo();
        }
        $('#'+name).hide();
    });
    $(".link").click(function(){
        var name = this.id;
        if(name=='P01'){ // algebra
            showAlgebra();
        } else if (name=='P17'){ // erlang
            showErlang();
        } else if (name=='P13'){ // jfizo
            showJfizo();
        }
        $('#'+name+'del').show();
        
    });

});

function generateList(lista){
	var size = lista.length;
	for(i=0;i<size;++i){
		var li = jQuery(
			$.create('li', 
					{'id':lista[i].id + 'p', 
					 'class':'menu'})
		).append(
			$.create('a',
					{'class': "link", 'id': lista[i].id, 'href': 'przedmiot/'+lista[i].id}, new Array(lista[i].nazwa)),
			$.create('a',
					{'class': "small", 'id': lista[i].id+'del', 'href': 'javascript:void(0)'}, new Array('.   ukryj'))
                    
		);
		$("#menu").append($(li));
		$('#' + lista[i].id+'del').hide();
	}
}

    function showErlang()
    {
        erlc1plus = document.getElementById("erlc1plus");
        erlw1plus = document.getElementById("erlw1plus");
        if (erlc1plus == null)
        {
        erlc1 = document.getElementById("erlangc1");
        erlc2 = document.getElementById("erlangc2");
        erlc1.innerHTML = "<a href='#' class='add' id='erlc1plus' onclick='return toggleBackground(erlc1, erlc2, this);'>+</a>Kurs Erlanga<br />pracownia";
        erlc1.style.borderBottom="white 1px solid";
        erlc2.innerHTML = "sala 110";
        erlc2.style.borderTop="white 1px solid";
        }
        if (erlw1plus == null)
        {
        erlw1 = document.getElementById("erlangw1");
        erlw2 = document.getElementById("erlangw2");
        erlw1.innerHTML = "<a href='#' class='add' id='erlw1plus' onclick='return toggleBackground(erlw1, erlw2, this);'>+</a>Kurs Erlanga<br />wykład";
        erlw1.style.borderBottom="white 1px solid";
        erlw2.innerHTML = "sala 119";
        erlw2.style.borderTop ="white 1px solid";
        }
        return false;
    }

    function showAlgebra()
    {
        c1plus = document.getElementById("c1plus");
        c2plus = document.getElementById("c2plus");
        w1plus = document.getElementById("w1plus");
        if (c1plus == null)
        {
        c11 = document.getElementById("algebrac11");
        c12 = document.getElementById("algebrac12");
        c11text = "<a href='#' class='add' id='c1plus' onclick='return toggleBackgroundHideRest(c11, c12, this, c21, c22, c21text, c22text);'>+</a>Algebra<br />ćwiczenia";
        c12text = "sala 4";
        c11.innerHTML = c11text;
        c11.style.borderBottom="white 1px solid";
        c12.innerHTML = c12text;
        c12.style.borderTop="white 1px solid";
        }
        if (c2plus == null)
        {
        c21 = document.getElementById("algebrac21");
        c22 = document.getElementById("algebrac22");
        c21text = "<a href='#' class='add' id='c2plus' onclick='return toggleBackgroundHideRest(c21, c22, this, c11, c12, c11text, c12text);'>+</a>Algebra<br />ćwiczenia";
        c22text = "sala 5";
        c21.innerHTML = c21text;
        c21.style.borderBottom="white 1px solid";
        c22.innerHTML = c22text;
        c22.style.borderTop="white 1px solid";
        }
        if (w1plus == null)
        {
        w1 = document.getElementById("algebraw1");
        w2 = document.getElementById("algebraw2");
        w1.innerHTML = "<a href='#' class='add' id='w1plus' onclick='return toggleBackground(w1, w2, this);'>+</a>Algebra<br />wykład";
        w1.style.borderBottom="white 1px solid";
        w2.innerHTML = "sala 25";
        w2.style.borderTop ="white 1px solid";
        }
        return false;
    }

    function hideErlang()
    {
        erlc1plus = document.getElementById("erlc1plus");
        erlw1plus = document.getElementById("erlw1plus");
        if (erlc1plus.innerHTML == "+")
        {
        erlc1plus.style.display = "none";
        erlc1.innerHTML = "";
        erlc2.innerHTML = "";
        erlc1.style.borderBottomColor = "black";
        erlc2.style.borderTopColor = "black";
        }
        if (erlw1plus.innerHTML == "+")
        {
        erlw1plus.style.display = "none";
        erlw1.innerHTML = "";
        erlw2.innerHTML = "";
        erlw1.style.borderBottomColor = "black";
        erlw2.style.borderTopColor = "black";
        }
        return false;
    }

    function hideAlgebra()
    {
        c1plus = document.getElementById("c1plus");
        c2plus = document.getElementById("c2plus");
        w1plus = document.getElementById("w1plus");
        if (c1plus != null && c1plus.innerHTML == "+")
        {
        c1plus.style.display = "none";
        c11.innerHTML = "";
        c12.innerHTML = "";
        c11.style.borderBottomColor = "black";
        c12.style.borderTopColor = "black";
        }
        if (c2plus != null && c2plus.innerHTML == "+")
        {
        c2plus.style.display = "none";
        c21.innerHTML = "";
        c22.innerHTML = "";
        c21.style.borderBottomColor = "black";
        c22.style.borderTopColor = "black";
        }
        if (w1plus.innerHTML == "+")
        {
        w1plus.style.display = "none";
        w1.innerHTML = "";
        w2.innerHTML = "";
        w1.style.borderBottomColor = "black";
        w2.style.borderTopColor = "black";
        }
        return false;
    }

    function toggleBackground(elem1, elem2, eplus)
    {
        if (eplus.innerHTML == "+")
        {
        elem1.style.backgroundColor = "#A8A8A8";
        elem1.style.borderBottomColor = "#A8A8A8";
        elem2.style.backgroundColor = "#A8A8A8";
        elem2.style.borderTopColor = "#A8A8A8";
        eplus.innerHTML = "-";
        }
        else
        {
        elem1.style.backgroundColor = "white";
        elem1.style.borderBottomColor = "white";
        elem2.style.backgroundColor = "white";
        elem2.style.borderTopColor = "white";
        eplus.innerHTML = "+";
        }
        eplus.style.backgroundColor = "white";
        return false;
    }

    function toggleBackgroundHideRest(elem1, elem2, eplus, rest1, rest2, rest1text, rest2text)
    {
        if (eplus.innerHTML == "+")
        {
        elem1.style.backgroundColor = "#A8A8A8";
        elem1.style.borderBottomColor = "#A8A8A8";
        elem2.style.backgroundColor = "#A8A8A8";
        elem2.style.borderTopColor = "#A8A8A8";
        eplus.innerHTML = "-";
        rest1.innerHTML = "";
        rest2.innerHTML = "";
        rest1.style.borderBottomColor = "black";
        rest2.style.borderTopColor = "black";
        rest2.style.backgroundColor = "white";
        rest1.style.backgroundColor = "white";
        }
        else
        {
        elem1.style.backgroundColor = "white";
        elem1.style.borderBottomColor = "white";
        elem2.style.backgroundColor = "white";
        elem2.style.borderTopColor = "white";
        eplus.innerHTML = "+";
        rest1.innerHTML = rest1text;
        rest2.innerHTML = rest2text;
        rest1.style.borderBottomColor = "white";
        rest2.style.borderTopColor = "white";
        }
        eplus.style.backgroundColor = "white";
        return false;
    }

		function showJfizo()
			{
			    jfc1plus = document.getElementById("jfc1plus");
				jfw1plus = document.getElementById("jfw1plus");
				if (typeof jfselected === 'undefined')
				{
					jfselected = "tab1";
				}
			    if (jfc1plus == null)
			    {
				jfc1 = document.getElementById("jfizoc1");
				jfc2 = document.getElementById("jfizoc2");
				jfc1.innerHTML += "<a href='#' id='tab1' class='tab selected' onclick='return toggleTab(this);'>sba</a>";
				jfc1.innerHTML += "<a href='#' id='tab2' class='tab' onclick='return toggleTab(this);'>aje</a>";
				jfc1.innerHTML += "<a href='#' id='tab3' class='tab' onclick='return toggleTab(this);'>jma</a>";
				jfc1.innerHTML += "<a href='#' id='tab4' class='tab' onclick='return toggleTab(this);'>jmi</a>";
				jfc1.innerHTML += "<a href='#' class='add' id='jfc1plus' onclick='return toggleBackgroundBlockTabs(jfc1, jfc2, this);'>+</a>JFiZO<br />ćwiczenia";
				jfc1.style.borderBottom="white 1px solid";
				jfc2.innerHTML = "sala 110";
				jfc2.style.borderTop="white 1px solid";
			    }
			    if (jfw1plus == null)
			    {
				jfw1 = document.getElementById("jfizow1");
				jfw2 = document.getElementById("jfizow2");
				jfw1.innerHTML = "<a href='#' class='add' id='jfw1plus' onclick='return toggleBackground(jfw1, jfw2, this);'>+</a>JFiZO<br />wykład";
				jfw1.style.borderBottom="white 1px solid";
				jfw2.innerHTML = "sala 119";
				jfw2.style.borderTop ="white 1px solid";
			    }
			    return false;
			}
    
    function hideJfizo()
    {
        jfc1plus = document.getElementById("jfc1plus");
        jfw1plus = document.getElementById("jfw1plus");
        if (jfc1plus.innerHTML == "+")
        {
            jfc1plus.style.display = "none";
            jfc1.innerHTML = "";
            jfc2.innerHTML = "";
            jfc1.style.borderBottomColor = "black";
            jfc2.style.borderTopColor = "black";
        }
        if (jfw1plus.innerHTML == "+")
        {
            jfw1plus.style.display = "none";
            jfw1.innerHTML = "";
            jfw2.innerHTML = "";
            jfw1.style.borderBottomColor = "black";
            jfw2.style.borderTopColor = "black";
        }
        return false;
    }

function toggleBackgroundBlockTabs(elem1, elem2, eplus)
{
    myTabs = ["tab1", "tab2", "tab3", "tab4"];
    if (eplus.innerHTML == "+")
    {
        elem1.style.backgroundColor = "#A8A8A8";
        elem1.style.borderBottomColor = "#A8A8A8";
        elem2.style.backgroundColor = "#A8A8A8";
        elem2.style.borderTopColor = "#A8A8A8";
        document.getElementById(jfselected).style.backgroundColor = "#A8A8A8";
        eplus.innerHTML = "-";
        for (e in myTabs)
        {
            document.getElementById(myTabs[e]).onclick = function() { return false; };
        }
    }
    else
    {
        elem1.style.backgroundColor = "white";
        elem1.style.borderBottomColor = "white";
        elem2.style.backgroundColor = "white";
        elem2.style.borderTopColor = "white";
        document.getElementById(jfselected).style.backgroundColor = "white";
        eplus.innerHTML = "+";
        for (e in myTabs)
        {
            document.getElementById(myTabs[e]).onclick = function() { return toggleTab(this); };
        }
    }
    eplus.style.backgroundColor = "white";
    return false;
}

function toggleTab(tab)
{
    myTabs = ["tab1", "tab2", "tab3", "tab4"];
    for (e in myTabs)
    {
        if (myTabs[e] == tab.id)
        {
            tab.style.borderRightStyle = "none";
            tab.style.backgroundColor = "white";
            jfselected = tab.id;
        }
        else
        {
            notTab = document.getElementById(myTabs[e]);
            notTab.style.borderRightStyle = "solid";
            notTab.style.backgroundColor = "#DBD7D8";
        }
    }
    return false;
}